home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 1
/
SPACE - Library 1 - Volume 1.iso
/
program
/
16
/
debug.fth
< prev
next >
Wrap
Text File
|
1985-11-19
|
5KB
|
161 lines
\ Debugger. Thanks, Mike Perry and Henry Laxen.
\
\ The debugger lets you single step the execution of a high level
\ definition. To invoke the debugger, type debug xxx where xxx is
\ the name of the word you wish to trace. When xxx executes, you will
\ get a single step trace showing you the word within xxx that
\ is about to execute, and the contents of the parameter stack.
\ Debugging makes everything run slightly slower, even outside
\ the word being debugged. see debug-off
\
\ debug name Mark that word for debugging
\ step Debug in single step mode
\ trace Debug in trace mode
\ debug-off Turn off the debugger (makes the system run fast again)
\ resume Exit from a pushed interpreter (see the f keystroke)
\
\ Keystroke commands while you're single-stepping:
\ d go down a level
\ u go up a level
\ c continue; trace without single stepping
\ g go; turn off tracing and continue execution
\ f push a Forth interpreter; resume to get back
\ q abort back to the top level
only forth also definitions
: label \ name ( -- )
create !csp
assembler [ assembler ] normal
;
: interpret-line \ input-line ( -- ?? )
prompt
tib 80 expect
tib span @ string-load
;
6 ualloc user debug-next
vocabulary bug bug also definitions
variable 'debug \ code field for high level trace
variable <ip \ lower limit of ip
variable ip> \ upper limit of ip
variable cnt \ how many times thru debug next
hex
variable slow-next? slow-next? off
\ Change all the next routines in the indicated range to jump through
\ the user area vector
code slow-next ( high low -- )
sp )+ a0 move
sp )+ a1 move
4eeb.0000 l# d1 lmove
'user# debug-next # d1 wmove \ 'user debug-next jmp instr. is in d1
begin
a1 a0 cmpa
u< while
205d.4ed0 l# a0 ) cmpi
0= if \ Replace the next instruction with 'user debug-next jmp
d1 a0 ) lmove
then
2 a0 addq
repeat
c;
\ Change all the next routines in the indicated range to perform the
\ in-line next routine
code fast-next ( high low -- )
sp )+ a0 move
sp )+ a1 move
4eeb.0000 l# d1 lmove
'user# debug-next # d1 wmove \ 'user debug-next jmp instr. is in d1
begin
a1 a0 cmpa
u< while
a0 ) d1 cmp
0= if \ Replace the jump instruction with the inline next routine
205d.4ed0 l# a0 ) lmove
then
2 a0 addq
repeat
c;
label fnext \ fix the >next code back to normal
205d.4ed0 l# 'user debug-next lmove
rts
end-code
label debnext
<ip l#) ip cmpa u> if
ip> l#) ip cmpa u<= if
cnt l#) d0 move 1 d0 addq d0 cnt l#) move
2 # d0 word cmp normal 0= if
0 d0 moveq d0 cnt l#) move fnext l#) jsr
'debug l#) a0 move a0 ) jmp
then then then
\ This is slightly different from the normal next (it has a nop)
\ so that it won't be clobbered by slow-next
ip )+ a0 move nop a0 ) jmp
end-code
code pnext (s -- ) \ Fix the next routine to use the debug version
\ Place a "debnext l#) jmp" instruction in the next area
4ef9 # 'user debug-next wmove
debnext l# 'user# debug-next 2+ up d) lmove
c;
code unbug (s -- ) \ Turn off debugging
fnext l#) jsr
c;
forth definitions
unbug
only forth also definitions
bug also definitions
: l.id (s anf len -- )
swap dup .id ( len anf acf )
c@ th 1f and ( len namelen )
- spaces
;
variable step? step? on
variable res
: (debug) (s low-adr hi-adr -- )
unbug 1 cnt ! ip> ! <ip ! pnext
slow-next? @ 0=
if here up@ user-size + slow-next
slow-next? on
then
;
: 'unnest (s pfa -- pfa' )
begin #align + dup token@ ['] unnest = until
;
\ Enter and leave the debugger
: (debug ( acf -- )
/token - dup 'unnest (debug)
;
: up1 ( ip -- ) dup find-cfa swap 'unnest (debug) ;
: (trace (s - )
." ( " .s ." )" cr \ Show stack
r@ @ >name td 10 l.id \ Show word name
step? @ key? or
if step? on res off ." --> " cursor-on key cursor-off upc
case
ascii D of r@ token@ (debug endof \ Down
ascii U of rp@ na1+ @ up1 endof \ Up
ascii C of step? @ not step? ! endof \ Continue
ascii F of begin interpret-line res @ until endof \ Forth
ascii G of <ip off ip> off endof \ Go
ascii Q of cr ." unbug" abort endof \ Quit
endcase
then
pnext
;
' (trace 'debug !
only forth bug also forth definitions
: debug \ name (s -- )
' (debug
;
: resume (s -- ) res on 0 pnext ;
: step (s -- ) step? on ;
: trace (s -- ) step? off ;
: debug-off (s -- )
unbug here up@ user-size + fast-next slow-next? off ;
only forth also definitions